<!DOCTYPE html>
<html>
<head>
  <title>自定义 - 实体列表</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
  <meta name="description" content="xms">
  <meta name="author" content="xms">
  <link rel="icon" href="/content/favicon.ico">

  <!-- Bootstrap core CSS -->
  <link href="/content/css/bootstrap3.3.5/bootstrap.min.css" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="/content/css/dashboard.css" rel="stylesheet">
  <link href="/content/css/font-awesome.min.css" rel="stylesheet">
  <link href="/content/customize/css/common.css" rel="stylesheet">
  <link href="/content/js/jquery-toast/jquery.toast.min.css" rel="stylesheet">
  <link id="themeLink" href="/content/css/theme/green.css" rel="stylesheet" />
  <!-- Bootstrap core JavaScript ================================================== -->
  <!-- Placed at the end of the document so the pages load faster -->
  <script src="/content/js/jquery.min.js"></script>
  <script src="/content/js/bootstrap.min.js"></script>
  <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  <script src="/content/js/ie10-viewport-bug-workaround.js"></script>
  <script src="/content/js/jquery.bootstrap.min.js"></script>
  <script src="/content/js/json2.js"></script>
  <script src="/content/js/xms.utility.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.core.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.widget.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js"></script>
  <script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js"></script>
  <script src="/content/js/jquery-toast/jquery.toast.min.js"></script>
  <script src="/content/js/xms.jquery.js"></script>
  <script src="/content/js/xms.web.js"></script>
  <script src="/content/js/xms.metadata.js"></script>
  <script src="/content/js/md5.js" type="text/javascript"></script>
  <script src="/content/js/commonlabels.js"></script>
  <script src="/content/js/common/pagecontext.js"></script>
  <script src="/api/user/usercontext"></script>
  <script>
    jQuery(function () {
      Xms.Web.Loading();
      function aLinkClick(e) {

        if (currentKeycode != 17 && window.parent && window.parent.addToTab) {
          e.preventDefault();
          var tabNav = $('#customTabNav', parent.document).children('.iframe-link-linkitem.active');
          var textEl = tabNav.clone();
          $(".glyphicon-remove", textEl).remove();
          var label = textEl.text();
          textEl = $(this).clone();
          $("span", textEl).remove();
          label = label + '-' + textEl.text();
          var link = $(this).attr("href");
          var id = $.md5(link);
          Xms.Web.callParentMethod('addToTab', { id: id, label: label, link: link });
          return false;
        } else {
          //  currentKeycode = -99999;
          //  var link = $(this).attr("href");
          //  Xms.Web.OpenWindow(link);
        }

      }
      var currentKeycode = -99999;
      $("body").on("click.customizeLinkclick", 'a[href]a:not([href^="javascript:"])a:not([href^="#"])', function (e) {
        aLinkClick.call(this, e);
      });
    });
  </script>
  <style>
    body {
      padding: 0;
      margin: 0;
    }

    .table-responsive {
      max-height: 400px;
      overflow-y: auto;
    }

    .panel-default .panel-heading {
      background-color: white;
    }
  </style>
  <link href="/content/js/jquery-ui-1.10.3/themes/base/jquery.ui.all.css" rel="stylesheet">
  <link href="/content/js/grid/pqgrid.dev.css" rel="stylesheet">
</head>
<body>
<div class="" id="body">
  <div class="clearfix">
    <div class="col-md-12" id="main">
      <div class="" style="padding:5px;" id="renderBody">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">
              <a data-toggle="collapse"
                 href="#collapseTwo">
                <strong>实体列表</strong>
              </a>
            </h3>
          </div>
          <div id="collapseTwo" class="panel-collapse collapse in">
            <div class="panel-body">
              <div id="gridview">
                <div class="mb-2 toolbar">
                  <form action="" method="get" id="searchForm" role="form">
                    <input type="hidden" name="EntityGroupId" id="EntityGroupId" value="" />
                    <div class="row">
                      <div class="col-sm-8">
                        <div class="btn-group btn-group-sm">
                          <a class="btn btn-info btn-with-params" href="/xms/customize/entity/create" id="createBtn"><span class="glyphicon glyphicon-plus-sign"></span> 新增</a>
                          <button type="button" class="btn btn-warning" data-action="/xms/api/schema/entity/deletebyid" data-role="delete" data-tooltip="删除"><span class="glyphicon glyphicon-trash"></span> 批量删除</button>
                          <button type="button" class="btn btn-default" data-action="/xms/api/schema/entity/setlogstate?state=true" data-role="update" data-tooltip="启用日志"><span class="glyphicon glyphicon-ok-circle"></span> 开日志</button>
                          <button type="button" class="btn btn-default" data-action="/xms/api/schema/entity/setlogstate?state=false" data-role="update" data-tooltip="禁用日志"><span class="glyphicon glyphicon-ban-circle"></span> 关日志</button>
                          <button type="button" class="btn btn-default" data-action="/xms/api/schema/entity/setauthstate?state=true" data-role="update" data-tooltip="启用权限"><span class="glyphicon glyphicon-ok-circle"></span> 开权限</button>
                          <button type="button" class="btn btn-default" data-action="/xms/api/schema/entity/setauthstate?state=false" data-role="update" data-tooltip="禁用权限"><span class="glyphicon glyphicon-ban-circle"></span> 关权限</button>
                        </div>
                      </div>
                      <div class="col-sm-4">
                        <div class="input-group input-group-sm">
                          <input name="name" type="text" class="form-control" placeholder="名称" />
                          <span class="input-group-btn">
                                        <button type="submit" class="btn btn-info btn-block grid-searcher"><span class="glyphicon glyphicon-search"></span> 查询</button>
                                    </span>
                        </div>
                      </div>
                    </div>
                  </form>
                  <!-- /input-group -->
                </div>

                <div class="table-datagrid-view">
                  <div class="datagrid-view"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <nav class="navbar navbar-default navbar-fixed-bottom hide" role="navigation" id="body-footer">
        <div class="container">
          <div class="navbar-form navbar-right" id="body-footer-content">
          </div>
        </div>
      </nav>
    </div>
  </div>
</div>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.button.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.mouse.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.autocomplete.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.draggable.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.resizable.js"></script>
<script src="/content/js/jquery-ui-1.10.3/ui/jquery.ui.tooltip.js"></script>
<script src="/content/js/fetch.js"></script>
<script src="/content/js/common/filters.js"></script>
<script src="/content/js/grid/pqgrid.dev.js"></script>
<script src="/content/js/grid/localize/pq-localize-zh.js"></script>
<script src="/content/js/cdatagrid.js"></script>
<script src="/content/js/jquery.bootpag.min.js"></script>
<script src="/content/js/jquery.form.js"></script>
<script>
  $(function () {
    var model = $.urlParamObj(location.href);
    $('#EntityGroupId').val(model.entitygroupid || '');
    $('.btn-with-params').each(function(){
      var _this = $(this);
      if(_this.attr('type') == 'button'){
        var url = _this.attr('data-action');
        url += (url.indexOf('?') > 0 ? "&" : "?");
        _this.attr('data-action', url + 'entitygroupid=' + model.entitygroupid);
      }
      else {
        var url = _this.attr('href');
        url += (url.indexOf('?') > 0 ? "&" : "?");
        _this.attr('href', url + 'entitygroupid=' + model.entitygroupid);
      }
    });
    var theaders = {
      'entity_name': '名称',
      'entity_localizedname': '显示名称',
      'entity_authorization': '权限',
      'entity_loged': '日志',
      'entity_createdon': '创建日期',
      'operation':'操作'
    }
    //列数据配置数据
    var columnConfigs = [
      //从新配置复选框列的渲染方式，
      {
        title: "", dataIndx: "recordid", maxWidth: 48, minWidth: 48, align: "center", resizable: false,
        type: 'checkBoxSelection', cls: 'ui-state-default', sortable: false, editable: false,
        render: function (ui) {
          //  console.log(ui)
          return '<input type="checkbox" value="' + ui.rowData.entityid + '" name="recordid" class="">'
        },
        cb: { all: true, header: true }
      },
      {
        title: "", dataIndx: "hidden", maxWidth: 30, minWidth: 30, align: "center", resizable: false,
        cls: 'ui-state-default', sortable: false, editable: false,
        hidden:true,
        render: function (ui) {
          //  console.log(ui)
          return '<input type="hidden" value="' + ui.rowData.entityid + '" name="componenttypename" class="">'
        },
        cb: { all: true, header: true }
      },
      { "dataIndx": "name", "title": theaders.entity_name, editable: false, "dataType": "string", "width": 250, "isprimaryfield": false, "attributetypename": "string" },
      { "dataIndx": "localizedname", "title": theaders.entity_localizedname, "dataType": "string", editable: false, "width": 150, "isprimaryfield": false, "attributetypename": "string" },
      {
        "dataIndx": "authorizationenabled", "title": theaders.entity_authorization, editable: false, "dataType": "string", "width": 100, "isprimaryfield": false, "attributetypename": "string", render: function (ui, a, b) {
          var datas = ui.rowData;
          var dataIndx = ui.dataIndx;
          var column = ui.column;
          var recordid = datas[dataIndx];

          if (recordid == true) {
            return '<span class="label label-success">启用</span>'
          } else {
            return '<span class="label label-default">禁用</span>'
          }
        }
      },
      { "dataIndx": "logenabled", "title": theaders.entity_loged, editable: false, "dataType": "string", "width": 100, "isprimaryfield": false, "attributetypename": "string", render: function (ui, a, b) {
          var datas = ui.rowData;
          var dataIndx = ui.dataIndx;
          var column = ui.column;
          var recordid = datas[dataIndx];

          if (recordid == true) {
            return '<span class="label label-success">启用</span>'
          } else {
            return '<span class="label label-default">禁用</span>'
          }
        } },
      { "dataIndx": "createdon", "title": theaders.entity_createdon, editable: false, "dataType": "string", "width": 150, "isprimaryfield": false, "attributetypename": "string" },
      {
        title: "操作", editable: false, minWidth: 120,width:120, notHeaderFilter: true, editable: false, sortable: false, render: function (ui) {
          var datas = ui.rowData;
          var dataIndx = ui.dataIndx;
          var column = ui.column;
          var recordid = datas[dataIndx];
          var html = ''
          if (datas.iscustomizable) {
            html = '<a class="btn btn-default btn-xs" href="'+ ORG_SERVERURL +'/customize/entity/edit?id=' + datas.entityid + '"><span class="glyphicon glyphicon-edit"></span> 编辑</a> <a class="btn btn-warning btn-xs" href=\'javascript:delRecord("' + datas.entityid + '","/api/schema/entity/deletebyid",false,deleteCallBack,null,"删除后相关数据也将一并删除，请提前备份数据",true)\'><span class="glyphicon glyphicon-trash"></span> 删除</a>';
          } else {
            html = '<a class="btn btn-default btn-xs" href="'+ ORG_SERVERURL +'/customize/entity/edit?id=' + datas.entityid + '"><span class="glyphicon glyphicon-edit"></span> 编辑</a>';
          }
          return html
        }
      }
    ];
    var url = ORG_SERVERURL + '/api/schema/entity/list?LoadData=true&';
    var $form = $('#searchForm');
    var roles_filters = new XmsFilter();
    var datagridconfig = {
      scrollModel: { autoFit: true },
      baseUrl: url,
      columnConfigs: columnConfigs,//字段配置信息
      context: $('#gridview'),//底部操作按钮方法触发
      filters: roles_filters,//post提交时过滤条件
      searchForm: $form//GET提交时查询的数据
    };
    $('.datagrid-view').xmsDataTable(datagridconfig);
    Xms.Web.Event.localStorageEvent.on('list_entity_rebind', function () {
      setTimeout(function () {
        location.reload();
      },100)
    });

  });
  function deleteCallBack() {
    $('#loader').remove();
    rebind();
    Xms.Web.Event.publish('refreshtree');
  }
  function rebind() {
    $('.datagrid-view').cDatagrid('refreshDataAndView');
  }

  function delRecord(id, action, refresh, onsuccess, onerror, confirmtext, isconfirmagain) {
    Xms.Web.Del(id, action, refresh, onsuccess, onerror, confirmtext, isconfirmagain, {

      content: '<div class="form-group"><h3 style="color:red; font-size:12px;"><label class="checkbox-inline"><input class="" style="font-size:12px; margin:0" id="anddeltable" type="checkbox" value="true" checked="checked" /><span style="font-size:18px;" class="pl-5">同时删除表？</span></label></h3></div>',
      checkOk: function (opts) {
        var ckb = $('#anddeltable').prop('checked');
        opts.postdata = {
          deletetable: ckb
        }

        return true;
      }
    });
  }
</script>
</body>
</html>
